package com.lsl.facade_pattern.example1.Facade;

import com.lsl.facade_pattern.example1.SubSystem.DwarvenCartOperator;
import com.lsl.facade_pattern.example1.SubSystem.DwarvenGoldDigger;
import com.lsl.facade_pattern.example1.SubSystem.DwarvenMineWorker;
import com.lsl.facade_pattern.example1.SubSystem.DwarvenTunnelDigger;

import java.util.Collection;
import java.util.List;

/**
 * 外观类
 *
 * @author Zed
 * @description
 * @date 2023/1/8 13:53
 */
public class DwarvenGoldmineFacade {

    private final List<DwarvenMineWorker> workers;

    /**
     * Constructor.
     */
    public DwarvenGoldmineFacade() {
        workers = List.of(
                new DwarvenGoldDigger(),
                new DwarvenCartOperator(),
                new DwarvenTunnelDigger());
    }

    public void startNewDay() {
        makeActions(workers, DwarvenMineWorker.Action.WAKE_UP, DwarvenMineWorker.Action.GO_TO_MINE);
    }

    public void digOutGold() {
        makeActions(workers, DwarvenMineWorker.Action.WORK);
    }

    public void endDay() {
        makeActions(workers, DwarvenMineWorker.Action.GO_HOME, DwarvenMineWorker.Action.GO_TO_SLEEP);
    }

    private static void makeActions(Collection<DwarvenMineWorker> workers, DwarvenMineWorker.Action... actions) {
        workers.forEach(worker -> worker.action(actions));
    }
}
